package com.example.springevent.event.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.example.springevent.event.bo.IvdAddedEventBO;
import com.example.springevent.event.event.IvdAddedEvent;

//@Component	// 未注册为bean，不是有效的事件监听器
@Order(value = 5)
public class IvdAddedEventPoListener implements ApplicationListener<IvdAddedEvent> {

	private static final Logger log = LoggerFactory.getLogger(IvdAddedEventPoListener.class);

	@Override
	public void onApplicationEvent(IvdAddedEvent event) {
		log.info("事件监听IvdAddedEventPoListener.onApplicationEvent。Thread={}, order=5:",
				Thread.currentThread().getName());
		IvdAddedEventBO ivd = event.getIvdAddedEventBO();
		System.out.println(String.format("订单[%s]增加核销金额[%s]", ivd.getPoCode(), ivd.getVerifyAmt()));
		Assert.isTrue(1 == 2); // 测试 抛出异常时，是否引起事件发布所在的事务回滚
	}

}
